home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World Interactive 7
/
PC World Interactive 7.iso
/
program
/
ctutord.EXE
/
TEMPLATE
< prev
next >
Wrap
Text File
|
1993-05-12
|
2KB
|
92 lines
/* section 1 */
#include <stdio.h>
/* section 2 */
/*
* This is an example of organizing a source file for use in a
* make believe project called operation codify.
*
* Operation codify is used to organize a source file in
* predictable format which can be used by all programmers working
* on the same project.
*
*/
/* section 3 */
#define ON 1
#define OFF 0
/*
* node definition of the binary tree.
*
*/
struct tree {
struct tree *right;/* pointer to right subtree */
struct tree *left; /* pointer to left subtree */
int data; /* numerical data to be stored in tree */
};
/*
* Function prototype - "buildtree": used to build the binary tree
*/
int buildtree( struct tree * );
/* section 4 */
/* Any global variables go here... */
/* section 5 - Start of Functions */
main()
{
int err; /* error flag, 0=ok, -1=error */
struct tree root; /* define the root node of the tree */
err=buildtree(&root);
/* check error condition, exit if problem */
if( err == -1 ){
printf("Buildtree could not allocate memory!\n");
/* return to op system */
exit();
}
/* ... */
}
/*
* buildtree
*
* Purpose: buildtree is responsible for building a binary tree
* which will be used to numerically sort a list of
* numbers. The list of numbers is stored in the tree
* one number at a time using the following algorithm:
*
* if( number < node value )
* go left
* else
* go right
*
* buildtree calls itself (recursive) when a value is found
* at the current node. When a value is not found, a new
* node is malloc'ed and initialize. buildtree is then
* called again with the address of the new node.
*
* Inputs:
* struct node * (pointer to a node structure)
*
* Outputs:
* int (error condition flag), possible values:
*
* 0 - all is well
* -1 - could not allocate memory correctly
*
*
* Lineage:
* John Doe 01/01/77 1.0 Original version
*
* (all mods will be identified here, along with their
* creator and the date.)
*
*/
int buildtree( struct tree *node )
{
/* ... */
}